﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Xml;
using System.Text;

public partial class create_new : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        submit_btn.Attributes.Add("onclick", "return confirm('Thank you for using our self-submission service. Press OK to Submit or Cancel to make changes');");
    }

    protected void submit_btn_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string cnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Database.accdb;Persist Security Info=True";
            string value = state_DD.Text;
            string selectState = "SELECT State_ID FROM State WHERE (State_Name = '" + value + "')";
            DataSet userDS = new DataSet();
            OleDbConnection db_conn1 = new OleDbConnection(cnStr);
            db_conn1.Open();
            OleDbDataAdapter db_dataAdapter = new OleDbDataAdapter(selectState, db_conn1);
            db_dataAdapter.Fill(userDS);
            db_conn1.Close();

            int state_numb = Int32.Parse(userDS.Tables[0].Rows[0].ItemArray[0].ToString());


            int user_id = Int32.Parse(Request.QueryString["user_id"]);  //Sets the Incident ID Number (used to query the Database) to the QueryString that was sent
            DateTime dt = DateTime.Parse("#" + DateTime.Now.ToShortDateString() + "#");

            string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Database.accdb;Persist Security Info=True";
            OleDbConnection db_conn = new OleDbConnection(connString);
            OleDbCommand insertStatement = new OleDbCommand("INSERT INTO [Incidents] ([User_ID], [Description], [Type], [Landmark], [City], [State], [Status], [Date Reported]) VALUES (@User_ID, @Description, @Type, @Landmark, @City, @State, @Status, @Date_Reported)", db_conn);
            insertStatement.Parameters.Add("User_ID", user_id);
            insertStatement.Parameters.Add("Description", desc_TB.Text);
            insertStatement.Parameters.Add("Type", type_TB.Text);
            insertStatement.Parameters.Add("Landmark", lm_TB.Text);
            insertStatement.Parameters.Add("City", city_TB.Text);
            insertStatement.Parameters.Add("State", state_numb);
            insertStatement.Parameters.Add("Status", "Verification");
            insertStatement.Parameters.Add("Date_Reported", dt);


            db_conn.Open();
            insertStatement.ExecuteNonQuery();
            db_conn.Close();

            Response.Redirect("~/Default.aspx");
        }
    }
}